﻿// Write a program that, for a given two integer numbers N and X, calculates the sumS = 1 + 1!/X + 2!/X2 + … + N!/XN

using System;

class SumFactorialDividedByPoweredX
{
    static void Main()
    {
        Console.Write("Enter X : ");
        string numberXStr = Console.ReadLine();
        int numberX;
        while (!int.TryParse(numberXStr, out numberX))
        {
            Console.Write("Invalid input. Enter integer X : ");
            numberXStr = Console.ReadLine();
        }

        Console.Write("Enter N : ");
        string numberNStr = Console.ReadLine();
        int numberN;
        while (!int.TryParse(numberNStr, out numberN))
        {
            Console.Write("Invalid input. Enter integer N : ");
            numberNStr = Console.ReadLine();
        }

        decimal factorial = 1;
        int power = 1;
        decimal sum = 1;
        for (int i = 1; i <= numberN; i++)
        {
            factorial *= i;
            power *= numberX;
            sum += factorial / power;
        }
        Console.WriteLine("The sum of 1 + 1!/X + 2!/X2 + … + N!/XN is {0}", sum);
    }
}
